home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / core.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  7.5 KB  |  206 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """distutils.core
  5.  
  6. The only module that needs to be imported to use the Distutils; provides
  7. the 'setup' function (which is to be called from the setup script).  Also
  8. indirectly provides the Distribution and Command classes, although they are
  9. really defined in distutils.dist and distutils.cmd.
  10. """
  11. __revision__ = '$Id: core.py 65806 2008-08-18 11:13:45Z marc-andre.lemburg $'
  12. import sys
  13. import os
  14. from types import *
  15. from distutils.debug import DEBUG
  16. from distutils.errors import *
  17. from distutils.util import grok_environment_error
  18. from distutils.dist import Distribution
  19. from distutils.cmd import Command
  20. from distutils.config import PyPIRCCommand
  21. from distutils.extension import Extension
  22. USAGE = 'usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]\n   or: %(script)s --help [cmd1 cmd2 ...]\n   or: %(script)s --help-commands\n   or: %(script)s cmd --help\n'
  23.  
  24. def gen_usage(script_name):
  25.     script = os.path.basename(script_name)
  26.     return USAGE % vars()
  27.  
  28. _setup_stop_after = None
  29. _setup_distribution = None
  30. setup_keywords = ('distclass', 'script_name', 'script_args', 'options', 'name', 'version', 'author', 'author_email', 'maintainer', 'maintainer_email', 'url', 'license', 'description', 'long_description', 'keywords', 'platforms', 'classifiers', 'download_url', 'requires', 'provides', 'obsoletes')
  31. extension_keywords = ('name', 'sources', 'include_dirs', 'define_macros', 'undef_macros', 'library_dirs', 'libraries', 'runtime_library_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', 'swig_opts', 'export_symbols', 'depends', 'language')
  32.  
  33. def setup(**attrs):
  34.     """The gateway to the Distutils: do everything your setup script needs
  35.     to do, in a highly flexible and user-driven way.  Briefly: create a
  36.     Distribution instance; find and parse config files; parse the command
  37.     line; run each Distutils command found there, customized by the options
  38.     supplied to 'setup()' (as keyword arguments), in config files, and on
  39.     the command line.
  40.  
  41.     The Distribution instance might be an instance of a class supplied via
  42.     the 'distclass' keyword argument to 'setup'; if no such class is
  43.     supplied, then the Distribution class (in dist.py) is instantiated.
  44.     All other arguments to 'setup' (except for 'cmdclass') are used to set
  45.     attributes of the Distribution instance.
  46.  
  47.     The 'cmdclass' argument, if supplied, is a dictionary mapping command
  48.     names to command classes.  Each command encountered on the command line
  49.     will be turned into a command class, which is in turn instantiated; any
  50.     class found in 'cmdclass' is used in place of the default, which is
  51.     (for command 'foo_bar') class 'foo_bar' in module
  52.     'distutils.command.foo_bar'.  The command class must provide a
  53.     'user_options' attribute which is a list of option specifiers for
  54.     'distutils.fancy_getopt'.  Any command-line options between the current
  55.     and the next command are used to set attributes of the current command
  56.     object.
  57.  
  58.     When the entire command-line has been successfully parsed, calls the
  59.     'run()' method on each command object in turn.  This method will be
  60.     driven entirely by the Distribution object (which each command object
  61.     has a reference to, thanks to its constructor), and the
  62.     command-specific options that became attributes of each command
  63.     object.
  64.     """
  65.     global _setup_distribution
  66.     klass = attrs.get('distclass')
  67.     if klass:
  68.         del attrs['distclass']
  69.     else:
  70.         klass = Distribution
  71.     if 'script_name' not in attrs:
  72.         attrs['script_name'] = os.path.basename(sys.argv[0])
  73.     
  74.     if 'script_args' not in attrs:
  75.         attrs['script_args'] = sys.argv[1:]
  76.     
  77.     
  78.     try:
  79.         _setup_distribution = dist = klass(attrs)
  80.     except DistutilsSetupError:
  81.         msg = None
  82.         if 'name' in attrs:
  83.             raise SystemExit, 'error in %s setup command: %s' % (attrs['name'], msg)
  84.         'name' in attrs
  85.         raise SystemExit, 'error in setup command: %s' % msg
  86.  
  87.     if _setup_stop_after == 'init':
  88.         return dist
  89.     dist.parse_config_files()
  90.     if _setup_stop_after == 'config':
  91.         return dist
  92.     
  93.     try:
  94.         ok = dist.parse_command_line()
  95.     except DistutilsArgError:
  96.         _setup_stop_after == 'config'
  97.         msg = _setup_stop_after == 'config'
  98.         None if DEBUG else _setup_stop_after == 'init'
  99.         raise SystemExit, gen_usage(dist.script_name) + '\nerror: %s' % msg
  100.     except:
  101.         _setup_stop_after == 'config'
  102.  
  103.     if DEBUG:
  104.         print 'options (after parsing command line):'
  105.         dist.dump_option_dicts()
  106.     
  107.     if _setup_stop_after == 'commandline':
  108.         return dist
  109.     if ok:
  110.         
  111.         try:
  112.             dist.run_commands()
  113.         except KeyboardInterrupt:
  114.             _setup_stop_after == 'commandline'
  115.             _setup_stop_after == 'commandline'
  116.             raise SystemExit, 'interrupted'
  117.         except (IOError, os.error):
  118.             _setup_stop_after == 'commandline'
  119.             exc = _setup_stop_after == 'commandline'
  120.             _setup_stop_after == 'commandline'
  121.             error = grok_environment_error(exc)
  122.             if DEBUG:
  123.                 sys.stderr.write(error + '\n')
  124.                 raise 
  125.             DEBUG
  126.             raise SystemExit, error
  127.         except (DistutilsError, CCompilerError):
  128.             _setup_stop_after == 'commandline'
  129.             msg = _setup_stop_after == 'commandline'
  130.             _setup_stop_after == 'commandline'
  131.             if DEBUG:
  132.                 raise 
  133.             DEBUG
  134.             raise SystemExit, 'error: ' + str(msg)
  135.         except:
  136.             _setup_stop_after == 'commandline'<EXCEPTION MATCH>KeyboardInterrupt
  137.         
  138.  
  139.     _setup_stop_after == 'commandline'
  140.     return dist
  141.  
  142.  
  143. def run_setup(script_name, script_args = None, stop_after = 'run'):
  144.     """Run a setup script in a somewhat controlled environment, and
  145.     return the Distribution instance that drives things.  This is useful
  146.     if you need to find out the distribution meta-data (passed as
  147.     keyword args from 'script' to 'setup()', or the contents of the
  148.     config files or command-line.
  149.  
  150.     'script_name' is a file that will be run with 'execfile()';
  151.     'sys.argv[0]' will be replaced with 'script' for the duration of the
  152.     call.  'script_args' is a list of strings; if supplied,
  153.     'sys.argv[1:]' will be replaced by 'script_args' for the duration of
  154.     the call.
  155.  
  156.     'stop_after' tells 'setup()' when to stop processing; possible
  157.     values:
  158.       init
  159.         stop after the Distribution instance has been created and
  160.         populated with the keyword arguments to 'setup()'
  161.       config
  162.         stop after config files have been parsed (and their data
  163.         stored in the Distribution instance)
  164.       commandline
  165.         stop after the command-line ('sys.argv[1:]' or 'script_args')
  166.         have been parsed (and the data stored in the Distribution)
  167.       run [default]
  168.         stop after all commands have been run (the same as if 'setup()'
  169.         had been called in the usual way
  170.  
  171.     Returns the Distribution instance, which provides all information
  172.     used to drive the Distutils.
  173.     """
  174.     global _setup_stop_after, _setup_stop_after
  175.     if stop_after not in ('init', 'config', 'commandline', 'run'):
  176.         raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,)
  177.     stop_after not in ('init', 'config', 'commandline', 'run')
  178.     _setup_stop_after = stop_after
  179.     save_argv = sys.argv
  180.     g = {
  181.         '__file__': script_name }
  182.     l = { }
  183.     
  184.     try:
  185.         
  186.         try:
  187.             sys.argv[0] = script_name
  188.             if script_args is not None:
  189.                 sys.argv[1:] = script_args
  190.             
  191.             exec open(script_name, 'r').read() in g, l
  192.         finally:
  193.             sys.argv = save_argv
  194.             _setup_stop_after = None
  195.  
  196.     except SystemExit:
  197.         pass
  198.     except:
  199.         raise 
  200.  
  201.     if _setup_distribution is None:
  202.         raise RuntimeError, "'distutils.core.setup()' was never called -- perhaps '%s' is not a Distutils setup script?" % script_name
  203.     _setup_distribution is None
  204.     return _setup_distribution
  205.  
  206.